﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using HotelManagement._04.OBJECT;

namespace HotelManagement._03.DAO
{
    class CheckOutDAO
    {
        DbConnection m_conn;
        SqlCommand m_command;
        SqlDataAdapter m_adap;

        public CheckOutDAO()
        {
            m_conn = new DbConnection();
        }

        public DataTable ViewCheckIn(string ip_procedure)
        {
            m_command = new SqlCommand(ip_procedure, m_conn.Connect());
            m_command.CommandType = CommandType.StoredProcedure;
            DataTable v_dt = new DataTable();
            m_adap = new SqlDataAdapter(m_command);
            try
            {
                m_adap.Fill(v_dt);
                m_conn.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            return v_dt;
        }
        public DataTable ViewInfoCustomer(int ip_checkInID, string ip_procedure)
        {
            try
            {
                m_command = new SqlCommand(ip_procedure, m_conn.Connect());
                m_command.CommandType = CommandType.StoredProcedure;
                m_command.Parameters.Add("@CheckInID ", SqlDbType.BigInt).Value = ip_checkInID;
                m_adap = new SqlDataAdapter(m_command);

                DataTable v_dt = new DataTable();
                m_adap.Fill(v_dt);
                m_conn.Close();
                return v_dt;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            return null;
        }

        public DataTable ViewSearchByCustomerName(string ip_CustomerName, string ip_procedure)
        {
            try
            {
                m_command = new SqlCommand(ip_procedure, m_conn.Connect());
                m_command.CommandType = CommandType.StoredProcedure;
                m_command.Parameters.Add("@CustomerName ", SqlDbType.NVarChar).Value = ip_CustomerName;
                m_adap = new SqlDataAdapter(m_command);

                DataTable v_dt = new DataTable();
                m_adap.Fill(v_dt);
                m_conn.Close();
                return v_dt;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            return null;
        }

        public DataTable GetCostByRoomID(string ip_RoomID, string ip_procedure)
        {
            try
            {
                m_command = new SqlCommand(ip_procedure, m_conn.Connect());
                m_command.CommandType = CommandType.StoredProcedure;
                m_command.Parameters.Add("@RoomID ", SqlDbType.NVarChar).Value = ip_RoomID;
                m_adap = new SqlDataAdapter(m_command);

                DataTable v_dt = new DataTable();
                m_adap.Fill(v_dt);
                m_conn.Close();
                return v_dt;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            return null;
        }

        public bool UpdateCheckOut(CheckOut ip_CheckOut, string ip_procedure)
        {
            try
            {
                m_command = new SqlCommand(ip_procedure, m_conn.Connect());
                m_command.CommandType = CommandType.StoredProcedure;
                m_command.Parameters.Add("@CheckInID", SqlDbType.BigInt).Value = ip_CheckOut.CheckInID;
                m_command.Parameters.Add("@CheckOutID", SqlDbType.BigInt).Value = ip_CheckOut.CheckOutID;
                m_command.Parameters.Add("@RoomID", SqlDbType.NVarChar).Value = ip_CheckOut.RoomID;
                m_command.Parameters.Add("@CheckOutDate", SqlDbType.DateTime).Value = ip_CheckOut.CheckOutDate;
                m_command.Parameters.Add("@RentCost", SqlDbType.BigInt).Value = ip_CheckOut.RentCost;
                m_command.Parameters.Add("@UserID", SqlDbType.BigInt).Value = AssetsGS.instance.UserId;
                m_command.Parameters.Add("@Note", SqlDbType.NVarChar).Value = ip_CheckOut.Note;
                m_command.Parameters.Add("@Fines", SqlDbType.BigInt).Value = ip_CheckOut.Fines;
                m_adap = new SqlDataAdapter(m_command);
                m_command.ExecuteNonQuery();
                m_conn.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
                return false;
            }
            return true;
        }
        public bool UpdateRoom(CheckOut ip_CheckOut, string ip_procedure)
        {
            try
            {
                m_command = new SqlCommand(ip_procedure, m_conn.Connect());
                m_command.CommandType = CommandType.StoredProcedure;
                m_command.Parameters.Add("@RoomID", SqlDbType.NVarChar).Value = ip_CheckOut.RoomID;
                m_command.Parameters.Add("@Status", SqlDbType.NVarChar).Value = ip_CheckOut.Status;
   
                m_adap = new SqlDataAdapter(m_command);
                m_command.ExecuteNonQuery();
                m_conn.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
                return false;
            }
            return true;
        }
    }
}
